package com.insnow.knowshare.repository;

import com.insnow.knowshare.entity.Post;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDateTime;
import java.util.List;

public interface PostRepository extends JpaRepository<Post, Long> {
    List<Post> findByUserId(Long userId);
    List<Post> findByTitleContaining(String keyword);

    @Query("SELECT p.userId, COUNT(p) FROM Post p WHERE p.createdAt BETWEEN :start AND :end GROUP BY p.userId")
    List<Object[]> countPostsByUser(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
}